<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="layui.css" media="all">
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
</head>
<body>
<!--<blockquote class="layui-elem-quote">-->
<!--    <p class="layui-col-md-offset4">-->
<!--        修改密码：-->
<!--    </p>-->
<!--</blockquote>-->
<!--<div class="layui-fluid">-->
<!--    <div class="layui-col-md-offset4">-->
<!--<form class="layui-form" action="#" th:action="@{/user-updatepassword}" method="post">-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">原密码</label>-->
<!--        <div class="layui-input-inline">-->
<!--            <input type="password" name="old_password" required lay-verify="required" placeholder="请输入原密码" autocomplete="off" class="layui-input">-->
<!--        </div>-->
<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">新密码</label>-->
<!--        <div class="layui-input-inline">-->
<!--            <input type="password" name="new_password" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">-->
<!--        </div>-->
<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">重新输入新密码</label>-->
<!--        <div class="layui-input-inline">-->
<!--            <input type="password" name="renew_password" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">-->
<!--        </div>-->
<!--    </div>-->
<!--    <div class="layui-form-item">-->
<!--        <div class="layui-input-block">-->
<!--            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>-->
<!--&lt;!&ndash;            <button class="layui-icon layui-btn layui-btn-normal" id="window-comeback">返回</button>&ndash;&gt;-->
<!--        </div>-->
<!--    </div>-->
<!--</form>-->
<!--    </div>-->
<!--    <div class="layui-col-md-offset4" style="margin-top: 20px"><font color="red" th:text="${msg}"></font></div>-->
<!--</div>-->
<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">修改密码</li>
        <li>修改邮箱</li>

    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <blockquote class="layui-elem-quote">
                <p class="layui-col-md-offset4">
                    修改密码：
                </p>
            </blockquote>
            <div class="layui-fluid">
                <div class="layui-col-md-offset4">
                    <form class="layui-form" action="#" th:action="@{/user-updatepassword}" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">原密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="old_password" required lay-verify="required" placeholder="请输入原密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="new_password" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input" onkeyup="value=value.replace(/[\W]/g,'') "  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" maxlength="9">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">重新输入新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="renew_password" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <!--            <button class="layui-icon layui-btn layui-btn-normal" id="window-comeback">返回</button>-->
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-col-md-offset4" style="margin-top: 20px"><font color="red" th:text="${msg}"></font></div>
            </div>
        </div>
        <div class="layui-tab-item">
            <blockquote class="layui-elem-quote">
                <p class="layui-col-md-offset2">
                    修改邮箱：
                </p>
            </blockquote>
            <div class="layui-main" style="width: 700px;">
                <form class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱：</label>
                        <div class="layui-input-block">
                            <input id="email" type="email" name="username" class="layui-input" lay-verify="required"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱验证码：</label>
                        <div class="layui-input-block">
                            <input id="checkCode" type="text" name="checkCode" class="layui-input" lay-verify="required"/>
                            <button id="sendCheckCode" type="button" class="layui-btn layui-btn-normal">获取验证码</button>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="update">确认</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="/js/jquery-2.1.0.min.js" charset="utf-8"></script>
<script>
    //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function(){
        var element = layui.element;

        //…
    });
</script>
<script>
    layui.use("form",function () {
        var form = layui.form;
        var $ = layui.$;

        form.on("submit(update)",function (data) {
            var inputCheckCode = $("#checkCode").val();
            if (inputCheckCode == checkCode){
                $.ajax({
                    url:"/user-toupdateEmail",
                    type:"POST",
                    data:data.field,
                    async:false,
                    success:function (text) {
                        if ("ok" == text){
                            layer.alert("修改成功",function () {
                                window.location.href = "/user-updatepassword";
                            });
                        }else{
                            layer.alert("修改失败");
                        }
                    }
                });
            } else{
                layer.msg("验证码输入错误");
            }
            return false;
        });


        $("#sendCheckCode").click(function () {
            var email = $("#email").val();
            if (email == null || email == ""){
                layer.msg("请输入邮箱！！！");
                return;
            }
            var index = layer.open({
                type:3,
                content:"邮件发送中..."
            });

            $.ajax({
                url:"/user-updateEmail?email="+email,
                type:"get",
                success:function (text) {
                    if (text != null && text != ""){
                        layer.close(index);
                        layer.msg("已发送");
                        checkCode = text;
                        countDown();
                    } else{
                        layer.alert("获取失败，请重新获取")
                    }
                }
            });
        });

        var maxTime = 60;
        function countDown(){
            if (maxTime == 0){
                checkCode = "";
                $("#sendCheckCode").removeClass("layui-btn-disabled");
                $("#sendCheckCode").removeAttr("disabled")
                $("#sendCheckCode").html("获取验证码");
                maxTime = 60;
            }else{
                $("#sendCheckCode").attr("disabled","disabled");
                $("#sendCheckCode").addClass("layui-btn-disabled");
                form.render();
                $("#sendCheckCode").html(maxTime+"秒后重新获取");
                maxTime--;
                setTimeout(countDown,1000);
            }
        }

    });
</script>
</body>
</html>